package com.nbgs.demo.dao;

import com.nbgs.demo.model.Card;
import org.apache.ibatis.annotations.*;

public interface CardMapper {
    //添加用户的水卡信息
    @Insert("insert into t_card(card_num,meter_id,user_id,area_num,type_id) value(#{cardNum},#{meterId},#{userId},#{areaNum},#{typeId})")
    @Options(useGeneratedKeys=true, keyProperty="cardId", keyColumn="card_id")
    void addCard(Card card);
   //通过用水性质名，找到用水type_id
    @Select("select type_id from t_type where type=#{type}")
    int findTypeIdByType(String type);

    //通过水卡号修改水卡号
    @Update("<script>\n" +
            "update t_card\n" +
            "<set>\n" +
            "<if test=\"cardNum!=null and cardNum!=''\">\n" +
            " card_num=#{cardNum}\n" +
            "</if>\n" +
            "</set>\n" +
            "where meter_id=#{meterId}\n"+
            "</script>\n")
    void updateCard(@Param(value = "meterId") int meterId, @Param(value="cardNum") String cardNum);
}
